package com.dong.zhaofengcontact2018.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.dong.zhaofengcontact2018.R;
import com.dong.zhaofengcontact2018.database.SqlMethod;
import com.dong.zhaofengcontact2018.model.Folk;
import com.dong.zhaofengcontact2018.view.My_Editview_add_Listview_via_PopupWindow;

import java.util.ArrayList;

/**
 * 新增加一个用户
 */
public class NewPersonActivity extends AppCompatActivity {

    //
    private Button mButtonSubmit;
    //
    private My_Editview_add_Listview_via_PopupWindow mMyView_Name;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Phones;
    private My_Editview_add_Listview_via_PopupWindow mMyView_NickName;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Unit;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Dept;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Rank;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Office;
    private My_Editview_add_Listview_via_PopupWindow mMyView_RoomNumber;
    private My_Editview_add_Listview_via_PopupWindow mMyView_InPhones;
    private My_Editview_add_Listview_via_PopupWindow mMyView_OutPhones;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Address;
    private My_Editview_add_Listview_via_PopupWindow mMyView_InGroup;
    // TODO: 2018/8/15
    private My_Editview_add_Listview_via_PopupWindow mMyView_QQ;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Weixin;
    private My_Editview_add_Listview_via_PopupWindow mMyView_Email;

    private ArrayList<String> mInGroupList;
    private ArrayList<String> mUnitList;
    private ArrayList<String> mDeptList;
    private ArrayList<String> mRankList;
    private ArrayList<String> mOfficeList;
    private ArrayList<String> mRoomNumberList;
    private ArrayList<String> mInPhonesList;
    private ArrayList<String> mOutPhonesList;
    private ArrayList<String> mNickNameList;
    private ArrayList<String> mAddressList;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_person);

        initView();

        getListDataForPopupwindow();

        mButtonSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                savePerson();
                startActivity(new Intent(NewPersonActivity.this, ShowContactPhoneActivity.class));
                NewPersonActivity.this.finish();
            }
        });

    }

    private void savePerson() {
        Folk folk = new Folk();

        folk.setUnit(mMyView_Unit.getText());
        folk.setDept(mMyView_Dept.getText());
        folk.setRank(mMyView_Rank.getText());
        folk.setOffice(mMyView_Office.getText());
        folk.setRoomNumber(mMyView_RoomNumber.getText());
        folk.setInPhones(mMyView_InPhones.getText());
        folk.setOutPhones(mMyView_OutPhones.getText());
        folk.setName(mMyView_Name.getText());
        folk.setNickName(mMyView_NickName.getText());
        folk.setPhones(mMyView_Phones.getText());
        folk.setAddress(mMyView_Address.getText());
        folk.setInGroup(mMyView_InGroup.getText());
        // TODO: 2018/8/15
        folk.setQq(mMyView_QQ.getText());
        folk.setWeixin(mMyView_Weixin.getText());
        folk.setEmail(mMyView_Email.getText());

        // 保存到数据库
        SqlMethod sqlMethod = new SqlMethod(NewPersonActivity.this);
        sqlMethod.save(folk);
    }

    private void initView() {
        mButtonSubmit = findViewById(R.id.btn_submit__new_person);
        //
        mMyView_Name = findViewById(R.id.name_edittext__new_person);
        mMyView_Phones = findViewById(R.id.phones_edittext__new_person);
        mMyView_NickName = findViewById(R.id.nickName_edittext__new_person);
        mMyView_Unit = findViewById(R.id.unit_edittext__new_person);
        mMyView_Dept = findViewById(R.id.dept_edittext__new_person);
        mMyView_Rank = findViewById(R.id.rank_edittext__new_person);
        mMyView_Office = findViewById(R.id.office_edittext__new_person);
        mMyView_RoomNumber = findViewById(R.id.roomNumber_edittext__new_person);
        mMyView_InPhones = findViewById(R.id.inPhones_edittext__new_person);
        mMyView_OutPhones = findViewById(R.id.outPhones_edittext__new_person);
        mMyView_Address = findViewById(R.id.address_edittext__new_person);
        mMyView_InGroup = findViewById(R.id.inGroup_edittext__new_person);
        // TODO: 2018/8/15
        mMyView_QQ = findViewById(R.id.qq_edittext__new_person);
        mMyView_Weixin = findViewById(R.id.weixin_edittext__new_person);
        mMyView_Email = findViewById(R.id.email_edittext__new_person);
    }


    public ArrayList<String> getUnitList() {
        return mUnitList;
    }

    public ArrayList<String> getDeptList() {
        return mDeptList;
    }

    public ArrayList<String> getRankList() {
        return mRankList;
    }

    public ArrayList<String> getOfficeList() {
        return mOfficeList;
    }

    public ArrayList<String> getRoomNumberList() {
        return mRoomNumberList;
    }

    public ArrayList<String> getInPhonesList() {
        return mInPhonesList;
    }

    public ArrayList<String> getOutPhonesList() {
        return mOutPhonesList;
    }

    public ArrayList<String> getNickNameList() {
        return mNickNameList;
    }

    public ArrayList<String> getAddressList() {
        return mAddressList;
    }

    public ArrayList<String> getInGroupList() {
        return mInGroupList;
    }

    private void getListDataForPopupwindow() {
        mUnitList = getIntent().getStringArrayListExtra("unit");
        mDeptList = getIntent().getStringArrayListExtra("dept");
        mRankList = getIntent().getStringArrayListExtra("rank");
        mOfficeList = getIntent().getStringArrayListExtra("office");
        mRoomNumberList = getIntent().getStringArrayListExtra("roomNumber");
        mInPhonesList = getIntent().getStringArrayListExtra("inPhones");
        mOutPhonesList = getIntent().getStringArrayListExtra("outPhones");
        mNickNameList = getIntent().getStringArrayListExtra("nickName");
        mAddressList = getIntent().getStringArrayListExtra("address");
        mInGroupList = getIntent().getStringArrayListExtra("inGroup");
    }

}
